const Cami = require('../../model/Cami')
// 导入生存随机数模块
const stringRandom = require('string-random');
module.exports = async (req, res) => {
    // 检查权限
    if (!res.isrole()) {
        return
    }
    const { number, size } = req.body
    if (!number) {
        res.sendResult(null, 400, '请传递需要生成卡密的数量！')
        return
    }
    if (!size) {
        res.sendResult(null, 400, '请传递需要容量大小！')
        return
    }
    var arr = []
    for (var i = 0; i < number; i++) {
        var obj = {
            key: stringRandom(35),
            size
        }
        arr.push(obj)

    }
    let createcami = await Cami.bulkCreate(arr)
    if (!createcami) {
        res.sendResult(null, 422, '生成失败！')
        return
    }
    res.sendResult(null, 201, '生成成功！')

}